<?php


namespace app\api\validate;


use app\lib\exception\ParameterException;
use think\Exception;
use think\Validate;
use  think\Request;

class BaseValidate extends Validate
{
    public  function goCheck(){
        // 获取http传入的参数
        // 对这些参数做检验
        $request = Request::instance();
        $params = $request->param();
        $result =  $this->batch()->check($params);
      if (!$result){
        $e = new ParameterException([
            'msg' => $this->error
        ]);
        throw $e;
      }else{
          return true;
      }
    }

    protected function isPositiveInteger($value, $rule = '', $date = '', $field = '')
    {
        if (is_numeric($value) && is_int($value + 0) && ($value + 0) > 0){
            return true;
        }else{
            return false;
        }
    }

    protected  function isNotEmpty($value, $rule = '', $date = '', $field = ''){
        if (empty($value)){
            return false;
        }else{
            return true;
        }
    }

}